package com.young.test.customannotation;

import javax.inject.Named;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

@Named("customAnnotationPostProcessor")
public class CustomAnnotationPostProcessor implements BeanPostProcessor {

	public Object postProcessBeforeInitialization(Object bean, String beanName)
			throws BeansException {
		return bean;
	}

	public Object postProcessAfterInitialization(Object bean, String beanName)
			throws BeansException {
		if(bean.getClass().getAnnotation(Brand.class) != null){
			BrandType brandType = bean.getClass().getAnnotation(Brand.class).value();
			if(brandType != null){
				switch(brandType){
				case OD:
					if(bean instanceof BrandService){
						((BrandService)bean).setBrandName(BrandType.OD.name());
					}
					break;
				case BSD:
					if(bean instanceof BrandService){
						((BrandService)bean).setBrandName(BrandType.BSD.name());
					}
					break;
				}
			}
		}
		return bean;
	}

}
